package com.aiyige.utils.widget;

import com.aiyige.MyApp;
import com.aiyige.model.GeoItem;
import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


/**
 * Created by zhuyakun on 2017/8/23.
 */

public class GeoDataUtil {
    public static List<GeoItem> provinceList = new ArrayList<>();
    public static List<List<GeoItem>> cityList = new ArrayList<>();


    public static void initData() throws Exception {
        if (provinceList.isEmpty() || cityList.isEmpty()) {
            provinceList.clear();
            cityList.clear();
            Province[] provinceArray = JSON.parseObject(MyApp.getAppContext().getResources().getAssets().open("ChinaProvinceCity.json"), Province[].class);
            for (Province province : provinceArray) {
                provinceList.add(new GeoItem(province.name, province.id));
                List<GeoItem> cityListForThisProvince = new LinkedList<>();
                for (City city : province.city) {
                    cityListForThisProvince.add(new GeoItem(city.name, city.id));
                }
                if (cityListForThisProvince.isEmpty()) {
                    cityListForThisProvince.add(GeoItem.DUMMY_ITEM);
                }
                cityList.add(cityListForThisProvince);
            }
        }
    }

    public static class Province {
        public String id;

        public String name;

        public City[] city;
    }

    public static class City {
        public String id;

        public String cities;

        public String name;

        public String lng;

        public String code;

        public String shortName;

        public String lat;

        public String pinyin;
    }

}
